home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / CC_C / 0574.ZIP / $MAIN.ASM < prev    next >
Assembly Source File  |  1986-07-25  |  2KB  |  125 lines

  1. include %c86.inc
  2.     ttl    $MAIN, 1.01, 07-25-86 jwk
  3.  
  4. ;    main entry point for all C programs under C86
  5. ;    similar changes must be made for other compilers
  6.  
  7.     dseg
  8.  
  9.     extv    _sysuglo, word
  10.     extv    _sysvals, word
  11. htop    equ    _sysvals[2]
  12.     extv    _args, word
  13.  
  14. hem    db    0dh,0ah,'Not enough RAM to run!$'
  15.  
  16. dem    db    0dh,0ah,'DOS version 2.x or higher required!$'
  17.  
  18.     cseg
  19.  
  20.     extf    _main
  21.  
  22.     public    $main
  23.  
  24. $main    proc    near
  25.  
  26.     mov    ah,30h            ;check DOS version
  27.     int    21h
  28.     mov    dx,ss            ;save SS value
  29.     cmp    al,2
  30.     jnb    dok
  31.     mov    ds,dx            ;won't work with 1.x
  32.     mov    dx,offset dem
  33.     mov    ah,9
  34.     int    21h
  35.     int    20h            ;so get right out
  36.  
  37. dok:    mov    ax,cs:2            ;check RAM usage
  38.     sub    ax,dx            ;result is what's above code
  39.     cmp    ax,1000h        ;if <64K just use it
  40.     jna    m01            ;else cut back to 64K for DS/SS
  41. ; NOTE -- release unused RAM here to permit EXEC function later........
  42.     mov    ax,1000h
  43.  
  44. m01:    mov    cx,4            ;convert to byte count
  45.     shl    ax,cl
  46.     mov    si,80h            ;look at PSP buffer
  47.     mov    cl,byte ptr [cs:si]    ;get character count
  48.     add    cl,3
  49.     and    cl,0feh            ;force it to be even
  50.     sub    ax,cx            ;back up to leave space
  51.     mov    sp,ax            ;and set the SP
  52.     mov    di,ax
  53.     mov    ss:_args,ax        ;save pointer to args
  54.     assume    cs:code,ds:code,es:data,ss:data
  55.     mov    es,dx
  56.     cld
  57.     rep movsb            ;move to be above heap
  58.     assume    cs:code,ds:data,es:data,ss:data
  59.     mov    ds,dx            ;set Data Segment after move
  60.     mov    bp,cx            ;zero BP now
  61.  
  62.     mov    di,_sysuglo        ;start of heap per loader
  63.     mov    cx,_sysuglo[2]        ;size initialized by loader
  64.     add    htop,di            ;add to reserve
  65.     add    htop,cx            ;and increment by what's in use
  66.     cmp    htop,sp
  67.     jnb    herr
  68.     xor    ax,ax
  69.     rep    stosb            ;clear the free space
  70.     call    _main
  71.     jmp    short    ex1
  72. ;
  73. herr:    mov    ah,9
  74.     mov    dx,ss            ;be sure of DS
  75.     mov    ds,dx
  76.     mov    dx,offset hem
  77.     int    21h
  78.     mov    ax,00ffh        ;255=heap error
  79.     jmp    short    ex1
  80. ;
  81.     public    _exit
  82.  
  83. _exit:    push    bp
  84.     mov    bp,sp
  85.     mov    ax,4[bp]
  86. ex1:    mov    ah,4ch            ; exit, set ret value
  87.     int    21h
  88.  
  89.     public    $entry0
  90. $entry0:
  91.     pop    si
  92.     xor    ax,ax
  93.     jmp    short    entc
  94. ;
  95.  
  96.     public    $entry1
  97. $entry1:
  98.     pop    si
  99.     cld
  100.     db    2eh            ;CS: prefix
  101.     lodsb
  102.     mov    ah,0
  103.     jmp    short    entc
  104. ;
  105.  
  106.     public    $entry2
  107. $entry2:
  108.     pop    si
  109.     cld
  110.     db    2eh            ;CS: prefix
  111.     lodsw
  112. entc:    push    bp
  113.     mov    bp,sp
  114.     sub    sp,ax
  115.     cmp    sp,htop
  116.     jna    herr
  117.     jmp    si
  118. ;
  119.  
  120.     pend    $main
  121.  
  122. code    ends
  123.  
  124.     end
  125.